#include <QApplication>
#include "qmlapplicationviewer.h"
#include <QtNetwork/QFtp>
#include <QDebug>
#include <QTimer>
#include "ftp_manager.h"
#include <QDeclarativeContext>
#include "file_manager.h"

QmlApplicationViewer *viewer;
Ftp_manager *ftpManager;
File_manager *fileManager;

Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QScopedPointer<QApplication> app(createApplication(argc, argv));
    viewer = new QmlApplicationViewer;
    ftpManager = new Ftp_manager;
    fileManager = new File_manager();
//    ftpManager.setHost("192.168.1.3",21);
//    ftpManager.setLogin("yekmen","btr2002");
//    ftpManager.listage();

//    fileManager->Cd("c:/");
    QObject::connect(fileManager,SIGNAL(listingFini()),fileManager,SLOT(shareVar()));

    QObject::connect(ftpManager,SIGNAL(listingFinished()),ftpManager,SLOT(partageVar()));

    viewer->rootContext()->setContextProperty("ftpManager", ftpManager);
    viewer->rootContext()->setContextProperty("fileManager", fileManager);

    viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer->setMainQmlFile(QLatin1String("qml/QFilePower/main.qml"));
    viewer->showExpanded();

    return app->exec();
}

/************************************ FTP MANAGER ******************************/
void Ftp_manager::partageVar()
{
    viewer->rootContext()->setContextProperty("list_name",QVariant::fromValue(list_fileName));
    viewer->rootContext()->setContextProperty("list_size",QVariant::fromValue(list_fileName.size()));
    viewer->rootContext()->setContextProperty("list_fileSize",QVariant::fromValue(list_fileSize));
    viewer->rootContext()->setContextProperty("list_fileModified",QVariant::fromValue(list_last));


    viewer->rootContext()->setContextProperty("list_type",QVariant::fromValue(list_fileType));

    qDebug() <<"[FtpManager] Partage OK";
}
/********************************* FILE MANAGER **************************************/
void File_manager::shareVar()
{
    viewer->rootContext()->setContextProperty("list_name",QVariant::fromValue(list_fileName));
    viewer->rootContext()->setContextProperty("list_size",QVariant::fromValue(list_fileName.size()));
    viewer->rootContext()->setContextProperty("list_fileSize",QVariant::fromValue(list_fileSize));

    viewer->rootContext()->setContextProperty("list_type",QVariant::fromValue(list_fileType));
    qDebug() << "[FileManager] Partage OK";

}
